#ifndef QUADTREE_H
#define QUADTREE_H

#include <vector>
#include <SFML/Graphics.hpp>
#include "../system/CollisionData.h"

namespace binge
{

class Node
{
public:
    Node(void);
    Node(float x, float y, float w, float h);
    Node(const sf::Rect<float> areaRect);
    ~Node(void);

    void AddObject(int objId);

    Node* child[4];
    sf::Rect<float> area;
    bool pushed;
    std::vector<int> objects;
};

class Quadtree
{
public:
    Quadtree(int levels, int width, int height);
    ~Quadtree(void);

    void Setup(Node* node, int levels = 2); // 0 = 1x1 1 = 4x4 2 = 16x16 etc...

    // For the collision nodes
    void Update(CollisionData collision);
    void UpdateNodes(Node* node, int objId, sf::Rect<float> colRect);

private:
    int m_levels;
    Node* m_node;

public:
    // For collision testing
    std::vector<Node*> leafNodes;
    std::vector<Node*> collisionNodes;
};

} // namespace

#endif // QUADTREE_H
